// #include "mlir/IR/Dialect.h"
// #include "mlir/IR/MLIRContext.h"
#include "mlir/InitAllDialects.h" //mlir::registerAllDialects
#include "mlir/InitAllPasses.h"   //mlir::registerAllPasses
// #include "mlir/Pass/Pass.h"
// #include "mlir/Pass/PassManager.h"
// #include "mlir/Support/FileUtilities.h"
#include "mlir/Tools/mlir-opt/MlirOptMain.h" //mlir::MlirOptMain
// #include "llvm/Support/CommandLine.h"
// #include "llvm/Support/InitLLVM.h"
// #include "llvm/Support/SourceMgr.h"
// #include "llvm/Support/ToolOutputFile.h"
#include "core/JsonHardwareInfo.hpp"
#include "crypto/Crypto.h"
#include "hyper/Hyper.h"
#include "sst/SST.h"

void registerLowerPadMessagePass();
void registerLowerCryptoToX86WithoutSHA1ISAPass();
void registerLowerCryptoToHyperPass();
void registerLowerHyperPass();
void registerSSTLowerHyperPass();
void registerLowerHyperMemcpyPass();
void registerLowerHyperSSTMemcpyPass();
void registerDeviceSchedulePass();
void registerSSTDeviceSchedulePass();
void registerLowerCryptoToGpuPass();
// void registerLowerCryptoToSSTPass();
void registerLowerSSTToLLVMPass();
void registerLowerCryptoToCGRAPass();
void registerLowerCryptoToFPGAPass();

int main(int argc, char **argv) {
  // Register all MLIR passes.
  mlir::registerAllPasses();
  // Register customer passes.
  registerLowerPadMessagePass();
  registerLowerCryptoToGpuPass();
  // registerLowerCryptoToSSTPass();
  registerLowerSSTToLLVMPass();
  registerLowerCryptoToX86WithoutSHA1ISAPass();
  registerLowerCryptoToHyperPass();
  registerLowerHyperPass();
  registerSSTLowerHyperPass();
  registerLowerHyperMemcpyPass();
  registerLowerHyperSSTMemcpyPass();
  registerDeviceSchedulePass();
  registerSSTDeviceSchedulePass();
  registerLowerCryptoToCGRAPass();
  registerLowerCryptoToFPGAPass();

  mlir::DialectRegistry registry;
  // Register all MLIR core dialects.
  registerAllDialects(registry);
  // Register customer dialects.
  // clang-format off
  registry.insert<
  mlir::crypto::CryptoDialect,
  mlir::sst::SSTDialect,
  mlir::hyper::HyperDialect
  >();

  auto jsonpath = std::getenv("DESIGN_JSON_FILE");
  if (jsonpath){
    wafer::Root &HardwareInfo = wafer::Root::getInstance();
    HardwareInfo.initialize(jsonpath);
  }

  // clang-format on

  return mlir::failed(
      mlir::MlirOptMain(argc, argv, "mlir optimizer driver", registry));
}
